var a = require("../../requests/request.js");

getApp();

Page({
    data: {
        currentMainTab: 0,
        swiperMainTab: 0,
        currentTab: 0,
        swiperTab: 0,
        winWidth: 0,
        winHeight: 0,
        year: 2017,
        month: 1,
        suvpageindex: 1,
        jccpageindex: 1,
        xxcpageindex: 1,
        zxcpageindex: 1,
        mpvpageindex: 1,
        suvpageindex_zhishu: 1,
        jccpageindex_zhishu: 1,
        xxcpageindex_zhishu: 1,
        zxcpageindex_zhishu: 1,
        mpvpageindex_zhishu: 1,
        suvpageindex_koubei: 1,
        jccpageindex_koubei: 1,
        xxcpageindex_koubei: 1,
        zxcpageindex_koubei: 1,
        mpvpageindex_koubei: 1,
        suvlist: [],
        jcclist: [],
        xxclist: [],
        zxclist: [],
        mpvlist: [],
        suvlist_zhishu: [],
        jcclist_zhishu: [],
        xxclist_zhishu: [],
        zxclist_zhishu: [],
        mpvlist_zhishu: [],
        suvlist_koubei: [],
        jcclist_koubei: [],
        xxclist_koubei: [],
        zxclist_koubei: [],
        mpvlist_koubei: [],
        suvloading: !1,
        jccloading: !1,
        xxcloading: !1,
        zxcloading: !1,
        mpvloading: !1,
        suvover: !1,
        jccover: !1,
        xxcover: !1,
        zxcover: !1,
        mpvover: !1,
        pagesource: ""
    },
    onShareAppMessage: function() {
        this.data.month;
        return {
            title: "热销车型排行榜",
            path: "/pages/xiaoliang/xiaoliang?pagesource=wxshare"
        };
    },
    setIndexMonth: function() {
        var t = this, e = "";
        t.setData({
            suvloading: !0,
            jccloading: !0,
            xxcloading: !0,
            zxcloading: !0,
            mpvloading: !0
        }), a.getIndexMonth("suv", function(a) {
            var i = a;
            switch (t.setData({
                year: i.Year,
                month: i.DateNum
            }), t.data.currentMainTab) {
              case 0:
                e = t.data.month + "月全国销量";
                break;

              case 1:
                e = t.data.month + "月人气榜";
                break;

              case 2:
                e = t.data.month + "月口碑排行";
            }
            wx.setNavigationBarTitle({
                title: e
            }), t.getallcar();
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        });
    },
    onLoad: function(a) {
        var t = this, e = "";
        a.pagesource && (e = a.pagesource), t.setData({
            pagesource: e
        }), wx.getSystemInfo({
            success: function(a) {
                t.setData({
                    winWidth: a.windowWidth,
                    winHeight: a.windowHeight
                });
            }
        });
    },
    onShow: function() {},
    onReady: function(a) {
        this.setIndexMonth();
    },
    onPullDownRefresh: function() {
        this.setData({
            suvlist: [],
            jcclist: [],
            xxclist: [],
            zxclist: [],
            mpvlist: []
        }), this.setIndexMonth(), wx.stopPullDownRefresh();
    },
    clickCar: function(a) {
        var t = a.currentTarget.dataset.id, e = a.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../summary/summary?id=" + t + "&name=" + e
        });
    },
    swiperchange: function(a) {
        this.setData({
            currentTab: parseInt(a.detail.current)
        });
    },
    swichNav: function(a) {
        var t = this;
        if (this.data.currentTab === a.currentTarget.dataset.current) return !1;
        t.setData({
            currentTab: a.currentTarget.dataset.current,
            swiperTab: a.currentTarget.dataset.current
        });
    },
    swichMainTab: function(a) {
        var t = this;
        if (this.data.currentMainTab === parseInt(a.currentTarget.dataset.currentmain)) return !1;
        t.setData({
            currentMainTab: parseInt(a.currentTarget.dataset.currentmain),
            swiperMainTab: parseInt(a.currentTarget.dataset.currentmain),
            currentTab: 0,
            swiperTab: 0
        }), t.setIndexMonth();
    },
    getallcar: function() {
        var t = this;
        switch (t.setData({
            suvover: !1,
            jccover: !1,
            xxcover: !1,
            zxcover: !1,
            mpvover: !1
        }), t.setData({
            suvloading: !0,
            jccloading: !0,
            xxcloading: !0,
            zxcloading: !0,
            mpvloading: !0
        }), t.data.currentMainTab) {
          case 1:
            t.setData({
                suvlist_zhishu: [],
                suvpageindex_zhishu: 1
            }), t.setData({
                jcclist_zhishu: [],
                jccpageindex_zhishu: 1
            }), t.setData({
                xxclist_zhishu: [],
                xxcpageindex_zhishu: 1
            }), t.setData({
                zxclist_zhishu: [],
                zxcpageindex_zhishu: 1
            }), t.setData({
                mpvlist_zhishu: [],
                mpvpageindex_zhishu: 1
            }), t.setData({
                suvloading: !0,
                jccloading: !0,
                xxcloading: !0,
                zxcloading: !0,
                mpvloading: !0
            }), a.getBitAutoZhishu("all", t.data.year, t.data.month, 1, 20, function(a) {
                t.setData({
                    suvlist_zhishu: t.data.suvlist_zhishu.concat(a.suv.Data),
                    suvpageindex_zhishu: 2
                }), t.setData({
                    jcclist_zhishu: t.data.jcclist_zhishu.concat(a.jcx.Data),
                    jccpageindex_zhishu: 2
                }), t.setData({
                    xxclist_zhishu: t.data.xxclist_zhishu.concat(a.xxc.Data),
                    xxcpageindex_zhishu: 2
                }), t.setData({
                    zxclist_zhishu: t.data.zxclist_zhishu.concat(a.zxc.Data),
                    zxcpageindex_zhishu: 2
                }), t.setData({
                    mpvlist_zhishu: t.data.mpvlist_zhishu.concat(a.mpv.Data),
                    mpvpageindex_zhishu: 2
                }), t.setData({
                    suvloading: !1,
                    jccloading: !1,
                    xxcloading: !1,
                    zxcloading: !1,
                    mpvloading: !1
                });
            }, null, null);
            break;

          case 2:
            t.setData({
                suvlist_koubei: [],
                suvpageindex_koubei: 1
            }), t.setData({
                jcclist_koubei: [],
                jccpageindex_koubei: 1
            }), t.setData({
                xxclist_koubei: [],
                xxcpageindex_koubei: 1
            }), t.setData({
                zxclist_koubei: [],
                zxcpageindex_koubei: 1
            }), t.setData({
                mpvlist_koubei: [],
                mpvpageindex_koubei: 1
            }), t.setData({
                suvloading: !0,
                jccloading: !0,
                xxcloading: !0,
                zxcloading: !0,
                mpvloading: !0
            }), a.getBitAutoKoubei("all", t.data.year, t.data.month, 1, 20, function(a) {
                t.setData({
                    suvlist_koubei: t.data.suvlist_koubei.concat(a.suv.Data),
                    suvpageindex_koubei: 2
                }), t.setData({
                    jcclist_koubei: t.data.jcclist_koubei.concat(a.jcx.Data),
                    jccpageindex_koubei: 2
                }), t.setData({
                    xxclist_koubei: t.data.xxclist_koubei.concat(a.xxc.Data),
                    xxcpageindex_koubei: 2
                }), t.setData({
                    zxclist_koubei: t.data.zxclist_koubei.concat(a.zxc.Data),
                    zxcpageindex_koubei: 2
                }), t.setData({
                    mpvlist_koubei: t.data.mpvlist_koubei.concat(a.mpv.Data),
                    mpvpageindex_koubei: 2
                }), t.setData({
                    suvloading: !1,
                    jccloading: !1,
                    xxcloading: !1,
                    zxcloading: !1,
                    mpvloading: !1
                });
            }, null, null);
            break;

          case 0:
          default:
            t.setData({
                suvlist: [],
                suvpageindex: 1
            }), t.setData({
                jcclist: [],
                jccpageindex: 1
            }), t.setData({
                xxclist: [],
                xxcpageindex: 1
            }), t.setData({
                zxclist: [],
                zxcpageindex: 1
            }), t.setData({
                mpvlist: [],
                mpvpageindex: 1
            }), t.setData({
                suvloading: !0,
                jccloading: !0,
                xxcloading: !0,
                zxcloading: !0,
                mpvloading: !0
            }), a.getIndexData("all", t.data.year, t.data.month, 1, 20, 1, function(a) {
                t.setData({
                    suvlist: t.data.suvlist.concat(a.suv.Data),
                    suvpageindex: 2
                }), t.setData({
                    jcclist: t.data.jcclist.concat(a.jcx.Data),
                    jccpageindex: 2
                }), t.setData({
                    xxclist: t.data.xxclist.concat(a.xxc.Data),
                    xxcpageindex: 2
                }), t.setData({
                    zxclist: t.data.zxclist.concat(a.zxc.Data),
                    zxcpageindex: 2
                }), t.setData({
                    mpvlist: t.data.mpvlist.concat(a.mpv.Data),
                    mpvpageindex: 2
                }), t.setData({
                    suvloading: !1,
                    jccloading: !1,
                    xxcloading: !1,
                    zxcloading: !1,
                    mpvloading: !1
                });
            }, null, null);
        }
    },
    getsuv: function() {
        var t = this;
        if (1 != t.data.suvloading && 1 != t.data.suvover) switch (t.setData({
            suvover: !1
        }), t.setData({
            suvloading: !0
        }), t.data.currentMainTab) {
          case 1:
            a.getBitAutoZhishu("suv", t.data.year, t.data.month, t.data.suvpageindex_zhishu, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.suvlist_zhishu.concat(i), t.setData({
                    suvlist_zhishu: e,
                    suvpageindex_zhishu: t.data.suvpageindex_zhishu + 1
                }), t.setData({
                    suvloading: !1
                }), 0 == i.length && t.setData({
                    suvover: !0
                });
            }, null, null);
            break;

          case 2:
            a.getBitAutoKoubei("suv", t.data.year, t.data.month, t.data.suvpageindex_koubei, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.suvlist_koubei.concat(i), t.setData({
                    suvlist_koubei: e,
                    suvpageindex_koubei: t.data.suvpageindex_koubei + 1
                }), t.setData({
                    suvloading: !1
                }), 0 == i.length && t.setData({
                    suvover: !0
                });
            }, null, null);
            break;

          case 0:
          default:
            a.getIndexData("suv", t.data.year, t.data.month, t.data.suvpageindex, 20, 1, function(a) {
                var e = [], i = a.Data;
                e = t.data.suvlist.concat(i), t.setData({
                    suvlist: e,
                    suvpageindex: t.data.suvpageindex + 1
                }), t.setData({
                    suvloading: !1
                }), 0 == i.length && t.setData({
                    suvover: !0
                }), console.log(t.data.suvpageindex);
            }, null, null);
        }
    },
    getjcc: function() {
        var t = this;
        if (1 != t.data.jccloading && 1 != t.data.jccover) switch (t.setData({
            jccover: !1
        }), t.setData({
            jccloading: !0
        }), t.data.currentMainTab) {
          case 1:
            a.getBitAutoZhishu("jincouxingche", t.data.year, t.data.month, t.data.jccpageindex_zhishu, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.jcclist_zhishu.concat(i), t.setData({
                    jcclist_zhishu: e,
                    jccpageindex_zhishu: t.data.jccpageindex_zhishu + 1
                }), t.setData({
                    jccloading: !1
                }), 0 == i.length && t.setData({
                    jccover: !0
                });
            }, null, null);
            break;

          case 2:
            a.getBitAutoKoubei("jincouxingche", t.data.year, t.data.month, t.data.jccpageindex_koubei, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.jcclist_koubei.concat(i), t.setData({
                    jcclist_koubei: e,
                    jccpageindex_koubei: t.data.jccpageindex_koubei + 1
                }), t.setData({
                    jccloading: !1
                }), 0 == i.length && t.setData({
                    jccover: !0
                });
            }, null, null);
            break;

          case 0:
          default:
            a.getIndexData("jincouxingche", t.data.year, t.data.month, t.data.jccpageindex, 20, 1, function(a) {
                var e = [], i = a.Data;
                e = t.data.jcclist.concat(i), t.setData({
                    jcclist: e,
                    jccpageindex: t.data.jccpageindex + 1
                }), t.setData({
                    jccloading: !1
                }), 0 == i.length && t.setData({
                    jccover: !0
                });
            }, null, null);
        }
    },
    getxxc: function() {
        var t = this;
        if (1 != t.data.xxcloading && 1 != t.data.xxcover) switch (t.setData({
            xxcover: !1
        }), t.setData({
            xxcloading: !0
        }), t.data.currentMainTab) {
          case 1:
            a.getBitAutoZhishu("xiaoxingche", t.data.year, t.data.month, t.data.xxcpageindex_zhishu, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.xxclist_zhishu.concat(i), t.setData({
                    xxclist_zhishu: e,
                    xxcpageindex_zhishu: t.data.xxcpageindex_zhishu + 1
                }), t.setData({
                    xxcloading: !1
                }), 0 == i.length && t.setData({
                    xxcover: !0
                });
            }, null, null);
            break;

          case 2:
            a.getBitAutoKoubei("xiaoxingche", t.data.year, t.data.month, t.data.xxcpageindex_koubei, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.xxclist_koubei.concat(i), t.setData({
                    xxclist_koubei: e,
                    xxcpageindex_koubei: t.data.xxcpageindex_koubei + 1
                }), t.setData({
                    xxcloading: !1
                }), 0 == i.length && t.setData({
                    xxcover: !0
                });
            }, null, null);
            break;

          case 0:
          default:
            a.getIndexData("xiaoxingche", t.data.year, t.data.month, t.data.xxcpageindex, 20, 1, function(a) {
                var e = [], i = a.Data;
                e = t.data.xxclist.concat(i), t.setData({
                    xxclist: e,
                    xxcpageindex: t.data.xxcpageindex + 1
                }), t.setData({
                    xxcloading: !1
                }), 0 == i.length && t.setData({
                    xxcover: !0
                });
            }, null, null);
        }
    },
    getzxc: function() {
        var t = this;
        if (1 != t.data.zxcloading && 1 != t.data.zxcover) switch (t.setData({
            zxcover: !1
        }), t.setData({
            zxcloading: !0
        }), t.data.currentMainTab) {
          case 1:
            a.getBitAutoZhishu("zhongxingche", t.data.year, t.data.month, t.data.zxcpageindex_zhishu, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.zxclist_zhishu.concat(i), t.setData({
                    zxclist_zhishu: e,
                    zxcpageindex_zhishu: t.data.zxcpageindex_zhishu + 1
                }), t.setData({
                    zxcloading: !1
                }), 0 == i.length && t.setData({
                    zxcover: !0
                });
            }, null, null);
            break;

          case 2:
            a.getBitAutoKoubei("zhongxingche", t.data.year, t.data.month, t.data.zxcpageindex_koubei, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.zxclist_koubei.concat(i), t.setData({
                    zxclist_koubei: e,
                    zxcpageindex_koubei: t.data.zxcpageindex_koubei + 1
                }), t.setData({
                    zxcloading: !1
                }), 0 == i.length && t.setData({
                    zxcover: !0
                });
            }, null, null);
            break;

          case 0:
          default:
            a.getIndexData("zhongxingche", t.data.year, t.data.month, t.data.zxcpageindex, 20, 1, function(a) {
                var e = [], i = a.Data;
                e = t.data.zxclist.concat(i), t.setData({
                    zxclist: e,
                    zxcpageindex: t.data.zxcpageindex + 1
                }), t.setData({
                    zxcloading: !1
                }), 0 == i.length && t.setData({
                    zxcover: !0
                });
            }, null, null);
        }
    },
    getmpv: function() {
        var t = this;
        if (1 != t.data.mpvloading && 1 != t.data.mpvover) switch (t.setData({
            mpvover: !1
        }), t.setData({
            mpvloading: !0
        }), t.data.currentMainTab) {
          case 1:
            a.getBitAutoZhishu("mpv", t.data.year, t.data.month, t.data.mpvpageindex_zhishu, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.mpvlist_zhishu.concat(i), t.setData({
                    mpvlist_zhishu: e,
                    mpvpageindex_zhishu: t.data.mpvpageindex_zhishu + 1
                }), t.setData({
                    mpvloading: !1
                }), 0 == i.length && t.setData({
                    mpvover: !0
                });
            }, null, null);
            break;

          case 2:
            a.getBitAutoKoubei("mpv", t.data.year, t.data.month, t.data.mpvpageindex_koubei, 20, function(a) {
                var e = [], i = a.Data;
                e = t.data.mpvlist_koubei.concat(i), t.setData({
                    mpvlist_koubei: e,
                    mpvpageindex_koubei: t.data.mpvpageindex_koubei + 1
                }), t.setData({
                    mpvloading: !1
                }), 0 == i.length && t.setData({
                    mpvover: !0
                });
            }, null, null);
            break;

          case 0:
          default:
            a.getIndexData("mpv", t.data.year, t.data.month, t.data.mpvpageindex, 20, 1, function(a) {
                var e = [], i = a.Data;
                e = t.data.mpvlist.concat(i), t.setData({
                    mpvlist: e,
                    mpvpageindex: t.data.mpvpageindex + 1
                }), t.setData({
                    mpvloading: !1
                }), 0 == i.length && t.setData({
                    mpvover: !0
                });
            }, null, null);
        }
    }
});